using System;
using System.Web.UI;
using System.Web.UI.WebControls;
using BTOps;

public partial class BTOps_ReceivePort : Page
{
    protected void Page_Load(object sender, EventArgs e)
    {
        if (IsPostBack)
        {
            pnlReceivePortInfo.Visible = true;
            pnlReceivePortDetail.Visible = true;
        }
    }

    protected void ddlApps_DataBound(object sender, EventArgs e)
    {
        if (!String.IsNullOrEmpty(Request.QueryString["app"]))
        {
            string app = Request.QueryString["app"];
            if (ddlApps.Items.Contains(new ListItem(app)))
            {
                ddlApps.SelectedValue = app;
                pnlReceivePortInfo.Visible = true;
                pnlReceivePortDetail.Visible = true;
            }
        }
    }

    protected void ReceivePortDetailsDS_Inserting(object sender, ObjectDataSourceMethodEventArgs e)
    {
        BTReceivePort receivePort = (BTReceivePort)e.InputParameters["receivePort"];
        if (null != receivePort)
        {
            TextBox PortName = dvwReceivePort.FindControl("txtName") as TextBox;
            DropDownList Authentication = dvwReceivePort.FindControl("ddlAuthentication") as DropDownList;
            TextBox Description = dvwReceivePort.FindControl("txtDescription") as TextBox;

            receivePort.ApplicationName = ddlApps.SelectedValue;
            if (null != PortName)
                receivePort.Name = PortName.Text;
            if (null != Authentication)
                receivePort.Authentication = Convert.ToInt32(Authentication.SelectedValue);
            if (null != Description)
                receivePort.Description = Description.Text;
        }
    }

    protected void ReceivePortDetailsDS_Updating(object sender, ObjectDataSourceMethodEventArgs e)
    {
        BTReceivePort receivePort = (BTReceivePort)e.InputParameters["receivePort"];
        receivePort.ApplicationName = ddlApps.SelectedValue;
    }

    protected void dvwReceivePort_DataBound(object sender, EventArgs e)
    {
        if (null == dvwReceivePort.DataItem)
            dvwReceivePort.ChangeMode(DetailsViewMode.Insert);
    }
}